package com.alibaba.csp.sentinel.dashboard.rule.nacos.system;

import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.SystemRuleEntity;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.AbstractRuleProvider;
import com.alibaba.csp.sentinel.dashboard.rule.nacos.NacosConfigUtil;
import com.alibaba.csp.sentinel.slots.system.SystemRule;
import org.springframework.stereotype.Component;

/**
 * @author: baiml
 * @Title: SystemRuleNacosProvider
 * @ProjectName: 中台技术平台
 * @Depart 中台研发部
 * @Description:
 * @date: 2021/8/16 11:33
 */
@Component(NacosConfigUtil.BEAN_SYSTEM_RULE_PROVIDER)
public class SystemRuleNacosProvider extends AbstractRuleProvider<SystemRule, SystemRuleEntity> {
    @Override
    protected String getRulePostFix(String appName) {
        return appName + NacosConfigUtil.SYSTEM_DATA_ID_POSTFIX;
    }

    @Override
    protected Class<SystemRule> getDestType() {
        return SystemRule.class;
    }

    @Override
    protected SystemRuleEntity toRule(String appName, String ip, Integer port, SystemRule systemRule) {
        return SystemRuleEntity.fromSystemRule(appName, ip, port, systemRule);
    }
}
